package com.jason.java.demo.proxy;

import android.os.Bundle;
import android.view.View;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.jason.java.demo.R;

import java.lang.reflect.Proxy;

/**
 * @description: DynamicProxyActivity
 * @author: ChenBaoYang
 * @createDate: 2022/3/10 9:29 上午
 */
public class DynamicProxyActivity extends AppCompatActivity {

    private IAction action;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_dynamic_proxy);
        MyAction myAction = new MyAction(this);
        MyInvocationHandler handler = new MyInvocationHandler(myAction);
        action = (IAction) Proxy.newProxyInstance(IAction.class.getClassLoader(), new Class[]{IAction.class}, handler);

    }

    public void onStart(View view) {
        action.start("开始了");
    }

    public void onResume(View view) {
        action.resume();
    }

    public void onPause(View view) {
        action.pause();
    }

    public void onStop(View view) {
        action.stop();
    }
}
